package com.sfh.cpc.home.fragment;

import android.view.View;

import com.chad.library.adapter.base.BaseQuickAdapter;
import com.sfh.cpc.BaseSwipeRefreshMoreLayoutFragment;
import com.sfh.cpc.com.entity.EUser;
import com.sfh.cpc.com.entity.RspPage;
import com.sfh.cpc.com.server.INoteServer;
import com.sfh.cpc.home.adapter.CharmAdapter;
import com.sfh.cpc.home.model.RankingModel;
import com.sfh.lib.AppCacheManager;
import com.sfh.lib.mvvm.annotation.LiveDataMatch;

/**
 * 功能描述: 总魅力排行
 *
 * @author SunFeihu 孙飞虎
 * @date 2018/9/4
 */
public class UserCharmPageFragment extends BaseSwipeRefreshMoreLayoutFragment<RankingModel> {

    public static UserCharmPageFragment newFragment() {
        return new UserCharmPageFragment();
    }

    @Override
    public String getName() {
        return "魅力";
    }

    @Override
    public BaseQuickAdapter getAdapter() {
        return new CharmAdapter();
    }

    @Override
    public void loadPage(int nowPage) {
        this.getViewModel().pageCharm(nowPage);
    }


    @LiveDataMatch
    public void onPageSuccess(RspPage<EUser> data) {

        super.onPageData(data);
    }

    @Override
    public void onItemClick(BaseQuickAdapter adapter, View view, int position) {

        INoteServer noteServer = AppCacheManager.getCache(INoteServer.class.getSimpleName(), INoteServer.class);
        if (noteServer != null) {
            EUser user = (EUser) adapter.getItem(position);
            noteServer.openUserNote(getContext(), user.getUserId());
        }
    }
}
